Add remotes-config-dir to OstreeRepo
authorAlexander Larsson <alexl@redhat.com>
Fri, 8 Apr 2016 14:59:12 +0000 (16:59 +0200)
committerColin Walters (automation) <walters+githubbot@verbum.org>
Thu, 14 Apr 2016 16:21:01 +0000 (16:21 +0000)
This allows you to replace the default
$sysroot/$sysconfdir/ostree/repos.d string value, and to use a similar
feature for repos that are not the system repo.

In particular, this allows us to support /etc/xdg-app/remotes.d for
xdg-app.

Closes: #247
Approved by: cgwalters

src/libostree/ostree-repo-private.h
src/libostree/ostree-repo.c

index a2a996932e1f0fdce5f42e949f1bd870a33ead58..6a9092e94c4a112505c4362d212092ceb83dd2ab 100644 (file)
@@ -63,6 +63,7 @@ struct OstreeRepo {
   int uncompressed_objects_dir_fd;
   GFile *config_file;
   GFile *sysroot_dir;
+  char *remotes_config_dir;
 
   GFile *transaction_lock_path;
   GHashTable *txn_refs;
index 495e226174e88e2b58253023a3160f8cebe26525..72a254317b5804397a652a8639cd238059360dbe 100644 (file)
@@ -88,6 +88,7 @@ enum {
   PROP_0,
 
   PROP_PATH,
+  PROP_REMOTES_CONFIG_DIR,
   PROP_SYSROOT_PATH
 };
 
@@ -625,6 +626,7 @@ ostree_repo_finalize (GObject *object)
     (void) close (self->uncompressed_objects_dir_fd);
   g_clear_object (&self->config_file);
   g_clear_object (&self->sysroot_dir);
+  g_free (self->remotes_config_dir);
 
   g_clear_object (&self->transaction_lock_path);
 
@@ -664,6 +666,9 @@ ostree_repo_set_property(GObject         *object,
     case PROP_SYSROOT_PATH:
       self->sysroot_dir = g_value_dup_object (value);
       break;
+    case PROP_REMOTES_CONFIG_DIR:
+      self->remotes_config_dir = g_value_dup_string (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -686,6 +691,9 @@ ostree_repo_get_property(GObject         *object,
     case PROP_SYSROOT_PATH:
       g_value_set_object (value, self->sysroot_dir);
       break;
+    case PROP_REMOTES_CONFIG_DIR:
+      g_value_set_string (value, self->remotes_config_dir);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -739,6 +747,13 @@ ostree_repo_class_init (OstreeRepoClass *klass)
                                                         "",
                                                         G_TYPE_FILE,
                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+  g_object_class_install_property (object_class,
+                                   PROP_REMOTES_CONFIG_DIR,
+                                   g_param_spec_string ("remotes-config-dir",
+                                                        "",
+                                                        "",
+                                                        NULL,
+                                                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
   /**
    * OstreeRepo::gpg-verify-result:
@@ -2315,19 +2330,32 @@ append_one_remote_config (OstreeRepo      *self,
  out:
   return ret;
 }
-                                 
+
+static GFile *
+get_remotes_d_dir (OstreeRepo          *self)
+{
+  if (self->remotes_config_dir != NULL)
+    return g_file_resolve_relative_path (self->sysroot_dir, self->remotes_config_dir);
+  else if (ostree_repo_is_system (self))
+    return g_file_resolve_relative_path (self->sysroot_dir, SYSCONF_REMOTES);
+
+  return NULL;
+}
+
 static gboolean
 append_remotes_d (OstreeRepo          *self,
                   GCancellable        *cancellable,
                   GError             **error)
 {
   gboolean ret = FALSE;
-  g_autoptr(GFile) etc_ostree_remotes_d = NULL;
+  g_autoptr(GFile) remotes_d = NULL;
   g_autoptr(GFileEnumerator) direnum = NULL;
 
-  etc_ostree_remotes_d = g_file_resolve_relative_path (self->sysroot_dir, SYSCONF_REMOTES);
+  remotes_d = get_remotes_d_dir (self);
+  if (remotes_d == NULL)
+    return TRUE;
 
-  if (!enumerate_directory_allow_noent (etc_ostree_remotes_d, OSTREE_GIO_FAST_QUERYINFO, 0,
+  if (!enumerate_directory_allow_noent (remotes_d, OSTREE_GIO_FAST_QUERYINFO, 0,
                                         &direnum,
                                         cancellable, error))
     goto out;
@@ -2502,11 +2530,8 @@ ostree_repo_open (OstreeRepo    *self,
       ostree_repo_set_disable_fsync (self, TRUE);
   }
 
-  if (ostree_repo_is_system (self))
-    {
-      if (!append_remotes_d (self, cancellable, error))
-        goto out;
-    }
+  if (!append_remotes_d (self, cancellable, error))
+    goto out;
 
   if (!glnx_opendirat (self->repo_dir_fd, "tmp", TRUE, &self->tmp_dir_fd, error))
     goto out;